package com.xr.system.student.controller;

import com.xr.common.annotation.SystemLog;
import com.xr.common.enums.LogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.xr.common.axios.AxiosResult;
import com.xr.common.axios.AxiosEnum;
import com.xr.system.model.student.dto.StudentDto;
import com.xr.system.student.service.IStudentService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Student信息表
 *
 * @author fzh
 * @email e_341877120_mail@163.com
 * @date 2022-09-29 11:13:09
 */
@RestController
@RequestMapping("/api/v1/student")
public class StudentController {

	@Autowired
	private IStudentService iStudentService;

	/**
	 * 根据条件查询列表
	 * @param studentDto
	 * @return
	 */
	@GetMapping("/selectList")
	public AxiosResult selectList(StudentDto studentDto) {
		return iStudentService.selectList(studentDto);
	}

	/**
	 * 根据id查询单个
	 * @param id
	 * @return
	 */
	@GetMapping("/selectOneById/{id}")
	public AxiosResult selectOneById(@PathVariable Long id) {
		return iStudentService.selectOneById(id);
	}

	/**
	 * 根据条件分页查询
	 * @param currentPage
	 * @param pageSize
	 * @param studentDto
	 * @return
	 */
	@GetMapping("/selectPage/{currentPage}/{pageSize}")
	public AxiosResult selectPage(@PathVariable int currentPage, @PathVariable int pageSize, StudentDto studentDto) {
		return iStudentService.selectPage(currentPage, pageSize, studentDto);
	}

	/**
	 * 新增
	 * @param studentDto
	 * @return
	 */
	@SystemLog(module = "Student模块", type = LogType.INSERT, description = "新增Student信息")
	@PostMapping("/insert")
	public AxiosResult insert(@RequestBody StudentDto studentDto) {
		return iStudentService.insert(studentDto);
	}

	/**
	 * 更新
	 * @param studentDto
	 * @return
	 */
	@SystemLog(module = "Student模块", type = LogType.UPDATE, description = "更新Student信息")
	@PutMapping("/update")
	public AxiosResult update(@RequestBody StudentDto studentDto) {
		return iStudentService.update(studentDto);
	}

	/**
	 * 根据id删除单个
	 * @param id
	 * @return
	 */
	@SystemLog(module = "Student模块", type = LogType.DELETE, description = "删除Student信息")
	@DeleteMapping("/delete/{id}")
	public AxiosResult delete(@PathVariable Long id) {
		return iStudentService.delete(id);
	}

	/**
	 * 根据id集合批量删除
	 * @param idList
	 * @return
	 */
	@SystemLog(module = "Student模块", type = LogType.DELETE, description = "批量删除Student信息")
	@PostMapping("/deleteBatch")
	public AxiosResult deleteBatch(@RequestBody List<Long> idList) {
		return iStudentService.deleteBatch(idList);
	}

	/**
	 * 导入文件
	 * @param file
	 * @return
	 */
	@SystemLog(module = "Student模块", type = LogType.IMPORT, description = "导入Student信息")
	@PostMapping("/importFile")
	public AxiosResult importFile(MultipartFile file) {
		return iStudentService.importFile(file);
	}

	/**
	 * 导出文件
	 * @param response
	 */
	@SystemLog(module = "Student模块", type = LogType.EXPORT, description = "导出Student信息")
	@GetMapping("/exportFile")
	public AxiosResult exportFile(HttpServletResponse response) {
		iStudentService.exportFile(response);
		return AxiosResult.success(AxiosEnum.EXPORT_SUCCESS);
	}

}
